package com.imcode.setdemo;

import java.util.Objects;

public class Member {

    private String name;

    public Member(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Member{" +
                "name='" + name + '\'' +
                '}';
    }

    /**
     * name 相同返回ture 不同返回false
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        System.out.println("equals:" + o);
        if (this == o) return true;
        if (!(o instanceof Member)) return false;
        Member member = (Member) o;
        return Objects.equals(getName(), member.getName());
    }

    /**
     * name 的内容相同,hashCode就相同
     * @return
     */
    @Override
    public int hashCode() {
        int hashCode = Objects.hash(name);
        System.out.println("hashCode:" + hashCode);
        return hashCode;
    }
}
